package com.hwxm.ltim.config;

import io.github.cdimascio.dotenv.Dotenv;

/**
 * @Author：lyj
 * @Package：com.goods.config
 * @Project：goods
 * @name：EnvLoader
 * @Date：2025/06/12 18:33
 * @Filename：EnvLoader
 */
public class EnvLoader {
    public static void loadEnv() {
        Dotenv dotenv = Dotenv.configure()
                .directory("./")      // 默认是项目根目录
                .filename(".env")     // 默认就是 .env
                .load();

        // 如果你想让 Spring Boot application.yml 能读取这些值
        String dbUser = dotenv.get("DB_USER");
        String dbPassword = dotenv.get("DB_PASSWORD");
        String redisPassword = dotenv.get("REDIS_PASSWORD");
        String mailUsername = dotenv.get("MAIL_USERNAME");
        String mailPassword = dotenv.get("MAIL_PASSWORD");
        
        if (dbUser != null) System.setProperty("DB_USER", dbUser);
        if (dbPassword != null) System.setProperty("DB_PASSWORD", dbPassword);
        if (redisPassword != null) System.setProperty("REDIS_PASSWORD", redisPassword);
        if (mailUsername != null) System.setProperty("MAIL_USERNAME", mailUsername);
        if (mailPassword != null) System.setProperty("MAIL_PASSWORD", mailPassword);
    }
}
